package com.view.calculadoraip;

import com.util.calculadoraip.OperacoesIP;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.TextView;

public class ResolucaoActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_resolucao);
		

		Intent intent = getIntent();
		OperacoesIP op = new OperacoesIP();
		
		/*Instanciando os TextViews que recebem valores diretos */
		TextView textIp = (TextView) findViewById(R.id.textIP);
		TextView textNetId = (TextView) findViewById(R.id.textNetID);
		TextView textNetId2 = (TextView) findViewById(R.id.textNetID2);
		TextView textBroadcast = (TextView) findViewById(R.id.textBroadcast);
		TextView textMascara = (TextView) findViewById(R.id.textMascara);
		TextView textMascara2 = (TextView) findViewById(R.id.textMascara2);
		/*Instanciando os TextViews que recebem valores convertidos para Binarios */
		TextView textBin = (TextView) findViewById(R.id.textBin);
		TextView textMascaraBin = (TextView) findViewById(R.id.textMascaraBin);
		TextView textMascaraBin2 = (TextView) findViewById(R.id.textMascaraBin2);
		TextView textNetIdBin = (TextView) findViewById(R.id.textNetIDBin);
		TextView textBin2 = (TextView) findViewById(R.id.textBin2);		
		TextView textBits = (TextView) findViewById(R.id.textBits);
		
		
		/* Recebedo valores do intent */
		String ip = intent.getStringExtra("ip");
		String n = intent.getStringExtra("n");
		String b = intent.getStringExtra("b");
		String m = intent.getStringExtra("m");
		
		/* Preechendo os campos com os valores recebidos */
		textIp.setText(ip);
		textNetId.setText(n);
		textNetId2.setText(n);
		textBroadcast.setText(b);
		textMascara.setText(m);
		textMascara2.setText(m);
		/* Preechendo os campos com os valores recebidos convertidos para binario */
		textBin.setText(op.converterIP(ip));
		textBin2.setText(op.converterIP(ip));
		textMascaraBin.setText(op.converterIP(m));
		textMascaraBin2.setText(op.converterIP(m));
		textNetIdBin.setText(op.converterIP(n));
		/* Pega o bit que originou a mascara */
		textBits.setText(op.reverterMascara(m)+ " bits");
	}

	public void voltar (View view) {
		finish();
	}
	
	/* abre a tela ajuda do projeto*/
	public void abrirAjuda(View view){
		Intent intent = new Intent(this, AjudaActivity.class);
		startActivity(intent);
	}
	
}
